public class Solution{
    public int[] twoSum(int[] nums, int target) {
        int[] ans = new int[2];
        Map<Integer, Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hash.containsKey(target - nums[i])) {
                // 如果hash表中含有target-nums[i] , 直接返回i和
                ans[0] = i;
                ans[1] = hash.get(target - nums[i]);
                return ans;
            }
            hash.put(nums[i], i);
        }
        return ans;
    }
}